-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cgirgen: remove the var
expression fixup
#1482
cgirgen: remove the var
expression fixup
#1482
Conversation
For the sake of making detection of ill-formed MIR code easier, an internalAssert is temporarily added to the procedure.
Arguments to `var` parameters weren't hoisted correctly, resulting in arguments of `var` type that are not `HiddenAddr` expressions.
There are two places where hook calls are manually constructed, both which didn't wrap the first argument in a `nkHiddenAddr` tree.
Method dispatcher creation didn't account for `var` parameters, placing them in argument positions directly.
It only has a single callsite and is now short and simple enough to no longer warrant being a procedure. The assertion is also removed again.
var
argument fixupvar
expression fixup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor suggestions, nothing blocking, and one question.
@@ -3491,10 +3491,22 @@ proc hoistParamsUsedInDefault(c: PContext, call, letSection, defExpr: var PNode) | |||
newNodeI(nkEmpty, letSection.info), | |||
call[paramPos]) | |||
|
|||
call[paramPos] = newSymNode(hoistedVarSym) # Refer the original arg to its hoisted sym | |||
if hoistedVarSym.typ.kind == tyVar: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to consider any skipTypes/unwrapping because this is after generic resolution etc, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In part, yes. There's also the assumption throughout parts of the compiler that tyVar
cannot appear be nested in a tyAlias
or the like.
Co-authored-by: Saem Ghani <saemghani+github@gmail.com>
/merge |
Merge requested by: @saem Contents after the first section break of the PR description has been removed and preserved below:
|
Summary
Remove a fixup in
cgirgen
related tovar
parameters incgirgen
and correct the AST construction necessitating it. There's no change in
language semantics.
Details
In typed
PNode
AST,var
parameters always have to be dereferencedfirst, including when being passed to other
var
parameters (resultingin
(HiddenAddr (HiddenDeref x))
trees). Multiple transformations /places where AST is constructed in the compiler didn't produce AST
adhering to this.
The result was incorrect MIR code being generated (because the location
storing the
var
parameter was being passed to another parameter,not the location the
var
parameter references), though this didn'tcause any trouble so far.
cgirgen
detected this situation andadjusted its output accordingly, producing well-formed CGIR AST.
The sources of the problematic
PNode
AST were:semexprs
liftdestructors
cgmeth
They're changed to produce AST adhering to the aforementioned
requirements, and the fixup in
cgirgen
is removed.